-- 			面向对象

-- 			封装
Object={}
Object.id=1
function Object:Test()
	print(self.id)
end
function Object:new()
	local obj = {}
	self.__index=self

	obj.base=self

	setmetatable(obj,self)
	return obj
end

local  myObj=Object:new() 
print(myObj)
print(myObj.id)
myObj:Test();

-- 			继承
function Object:subClass(className)
	_G[className]={}
	local obj = _G[className]
	obj.__index=self;
	setmetatable(obj,self)
end
Object:subClass("Person")
local  p1=Person:new()  
print(p1.id) 


-- 			多态
Object:subClass("GameObject")
GameObject.posX=0;
GameObject.posY=0;
function  GameObject:Move()
	self.posY=self.posY+1
	self.posX=self.posX+1
	print(self.posX)
	print(self.posY)
end
GameObject:subClass("Player")
function  Player:Move()
	-- self.base:Move()//默认会把基类表当做第一个参数
	-- self.base.Move(self)//手动传入参数，避免把基类表传入
end
local p1 =Player:new()
p1:Move()